<?php 
$req_path="../";
include($req_path."includes/ini.php");
include($req_path."includes/db.php");

class M_Otherpay extends DB{
    private $rowCount=0;
    public $table_name="tb_otherpay";
    function M_Otherpay(){
		parent::__construct();
	//$this->dbConn=$this->getDB();
    }
   
    function loadData($month='', $name='' , $type='0'){
        
        $sqlscript= "SELECT id, DATE_FORMAT(month_pay,'%d/%m/%Y') monthpay , CASE WHEN type='O' THEN 'รายจ่ายอื่นๆ'  ELSE 'ค่าบริการ'  END as type, type as type_id , name ,amount ";
        $sqlscript.= "FROM ". $this->table_name;
        $sqlscript.= " WHERE 1=1 ";
		if ($name!=''){
			$sqlscript.=  " AND name like '%".$name."%'";
		}
		if ($month!=''){
			$sqlscript.=  " AND DATE_FORMAT(month_pay,'%m/%Y') = '".$month."'";
		}
		if ($type !='0'){
			$sqlscript.=  " AND type = '".$type."'";
		}
		// print_r($sqlscript);
        $result = $this->ExecuteData($sqlscript);
        $this->rowCount = $result->RecordCount();
        return $result;
    }
	   

    function getRowCount(){
        
        return $this->rowCount;
        
    }	
    function insertData($val){
            if (isset($val)){
				$sqlInsert=$this->InsertSqlScript("SELECT name,amount, type, month_pay , createdate, createby FROM ". $this->table_name." where 1=2 ", $val);
				$this->ExecuteData($sqlInsert);
            }
    }
	 
    function updateData($id,$val){
            if(isset($val)){
				$sqlUpdate=$this->UpdateSqlScript("SELECT name,amount,type, month_pay, updatedate, updateby FROM ". $this->table_name." where id='".$id."'" ,$val);
				 $this->ExecuteData($sqlUpdate);
				// return $sqlUpdate;
            }
    } 
    function deleData($id){
            if(isset($id)){
			$sqlDelete = "Delete FROM ". $this->table_name." where id='".$id."'";
			$this->ExecuteData($sqlDelete);
			return 1;
            }
    }
	 
}
?>
